-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jae/rangeprooffix #75
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments about documentation and exported methods.
LGTM in general. develop
needs to be merged in or rebased upon.
proof_range.go
Outdated
// `i` is the relative index within this RangeProof. | ||
// Also see LeftIndex(). | ||
// Verify that a key has some value. | ||
// Does not assume that the proof itself is valid, call Verify() first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is always intended to be used in combination with Verify()
, then it would safer if we do not expose this functionality. In other words: Is there a use-case where we need to call VerifyItem(...)
without Verify()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to call Verify without VerifyItem. If we're going to have a Verify() method, might as well have a separate VerifyItem method. We return an error if Verify() wasn't called first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't true here but it is true here now: #78
In multi-layered merkle proofs, say, it is more efficient to not have the intermediate root hashes in the layered merkle proofs, so in that case you'll want to verify the leaves, but compute the root hash and override the root hash verification requirement by calling:
proof.Verify(proof.ComputeRootHash())
which is cheap due to memoization (in the linked PR) and enables the other verification functionality.
proof_range.go
Outdated
@@ -236,24 +264,35 @@ func (proof *RangeProof) _verify(root []byte) (treeEnd bool, err error) { | |||
// If keyStart or keyEnd don't exist, the leaf before keyStart | |||
// or after keyEnd will also be included, but not be included in values. | |||
// If keyEnd-1 exists, no later leaves will be included. | |||
// If keyStart <= keyEnd and both not nil, panics. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be keyStart >= keyEnd
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah oops.
proof_range.go
Outdated
@@ -20,8 +21,21 @@ type RangeProof struct { | |||
treeEnd int // 0 if not set, 1 if true, -1 if false. | |||
} | |||
|
|||
func (proof *RangeProof) Keys() (keys [][]byte) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only used in the test below so far. Do you assume this will be useful for other purposes, too? As far as I can see, the keys are always returned (now) together with the range-proof (not sure why we need an additional public Keys()
method).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so yeah, the keys returned are the queried keys. the .Keys() in a RangeProof are all the keys for values queried + any other keys like the item before startKey if startKey is provided (not nil) and doesn't exist in the iavl store, so they're different in functionality. I'll add a comment saying so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Keys returns all the keys in the RangeProof. NOTE: The keys here may
// include more keys than provided by tree.GetRangeWithProof or
// VersionedTree.GetVersionedRangeWithProof. The keys returned there are only
// in the provided [startKey,endKey){limit} range. The keys returned here may
// include extra keys, such as:
// - the key before startKey if startKey is provided and doesn't exist;
// - the key after a queried key with tree.GetWithProof, when the key is absent.
func (proof *RangeProof) Keys() (keys [][]byte) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. That makes sense.
proof_range.go
Outdated
return proof.LeftPath.Index() | ||
} | ||
|
||
// `i` is the relative index within this RangeProof. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we need to explain what i
is here? It is not a parameter/argument nor do we return it. It looks like an implementation detail. Looks like this comment belongs inside of the method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in the new PR.
{start: 0xf8, end: 0x00, pnc: true}, // #19 | ||
{start: 0x10, end: 0x10, pnc: true}, // #20 | ||
{start: 0x12, end: 0x12, pnc: true}, // #21 | ||
{start: 0xff, end: 0xf7, pnc: true}, // #22 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exemplary testing 👍
I pushed fixes to #78 |
Reviewed #78. LGTM |
0.9.1 -- compute hash from rangeproof
Merged #78 and resolved conflicts to develop. Will merge if ci goes through. |
* VerifyItem takes no index; Return keys/values in range; Fix * compute hash from rangeproof * Require Verify() before Verify*() * Review fixes from #75 * Bump version, update changelog
0.9.1 -- compute hash from rangeproof Require Verify() before Verify*() Review fixes from cosmos#75 First commit for generalized merkle proofs Fix imports Bump version to 0.9.3 Return nil on empty tree - bump version to 0.10.0 Add OpDecoders fix test finalize rebase
0.9.1 -- compute hash from rangeproof Require Verify() before Verify*() Review fixes from cosmos#75 First commit for generalized merkle proofs Fix imports Bump version to 0.9.3 Return nil on empty tree - bump version to 0.10.0 Add OpDecoders fix test finalize rebase fix test
0.9.1 -- compute hash from rangeproof Require Verify() before Verify*() Review fixes from cosmos#75 First commit for generalized merkle proofs Fix imports Bump version to 0.9.3 Return nil on empty tree - bump version to 0.10.0 Add OpDecoders fix test finalize rebase fix test fix toml
* 'develop' of github.com:danil-lashin/iavl: Prep Release 0.11.0 (cosmos#111) Remove architecture dependent getter functions (cosmos#96) Use 8 bytes to store int64 components of database keys (cosmos#107) Update to CircleCI 2.0 (cosmos#108) Release 0.10.0: Update Changelog and bump version (cosmos#99) delete empty file (relict from merging master into develop) Mutable/Immutable refactor and GetImmutable snapshots (cosmos#92) Remove unreachable code Remove unused variable dep: Change tendermint dep to be ^v0.22.0 (cosmos#91) Fix benchmark scripts for current code (cosmos#89) release v0.9.2 (cosmos#82) Various lints (cosmos#80) Jae/rangeprooffix (cosmos#75)
* VerifyItem takes no index; Return keys/values in range; Fix * Bump version * 0.9.1 -- compute hash from rangeproof * Require Verify() before Verify*() * Review fixes from cosmos#75
* VerifyItem takes no index; Return keys/values in range; Fix * compute hash from rangeproof * Require Verify() before Verify*() * Review fixes from cosmos#75 * Bump version, update changelog
0.9.1 -- compute hash from rangeproof Require Verify() before Verify*() Review fixes from cosmos#75 First commit for generalized merkle proofs Fix imports Bump version to 0.9.3 Return nil on empty tree - bump version to 0.10.0 Add OpDecoders fix test finalize rebase fix test fix toml
0.9.0 (July 1, 2018)
BREAKING CHANGES
BUG FIXES
Merging to develop early since the previous version is just broken.